//
//  GuideViewController.m
//  FreeTrip
//
//  Created by 邓芮 on 15/12/1.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "GuideViewController.h"
#import "TabBarController.h"
@interface GuideViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    self.scrollView.delegate = self;
    self.scrollView.contentSize = CGSizeMake(KScreenWidth * 4, KScreenHeight);
    self.scrollView.contentOffset = CGPointMake(0, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.bounces = NO;
    [self.view addSubview:self.scrollView];
    
    for (int i = 0; i < 4; i++)
    {
        if (i < 3)
        {
            UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth * i, 0, KScreenWidth, KScreenHeight)];
            icon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
            [self.scrollView addSubview:icon];
        }
        else if(i == 3)
        {
            UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth * i, 0, KScreenWidth, KScreenHeight)];
            icon.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i]];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(0, KScreenHeight - 90 * KScreenWidth / 414, KScreenWidth, 30 * KScreenWidth / 414);
//            button.backgroundColor = [UIColor orangeColor];
            [button addTarget:self action:@selector(inland:) forControlEvents:UIControlEventTouchUpInside];
            [button setTitle:@"进入" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:20 * KScreenWidth / 414];
            icon.userInteractionEnabled = YES;
            [icon addSubview:button];
            [self.scrollView addSubview:icon];
            
        }
        
    }
    
    self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, KScreenHeight - 50 * KScreenWidth / 414, KScreenWidth, 30 * KScreenWidth / 414)];
//    self.pageControl.backgroundColor = [UIColor redColor];
    self.pageControl.numberOfPages = 4;
    self.pageControl.currentPage = 0;
    self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
    self.pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
    [self.pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.pageControl];
    
}

- (void)inland:(UIButton *)button
{
//    [(UIWindow *)[UIApplication sharedApplication].delegate window].rootViewController = [[TabBarController alloc]init];
    [[UIApplication sharedApplication] keyWindow].rootViewController = [[TabBarController alloc]init];
}

- (void)pageControlAction:(UIPageControl *)page
{
//    UIScrollView *scroll = self.view.subviews[0];
    [self.scrollView setContentOffset:CGPointMake(KScreenWidth * page.currentPage, 0) animated:YES];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = scrollView.contentOffset.x / KScreenWidth;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
